package com.wwj.admin.player.controller;

import com.wwj.core.wawa.entity.Player;
import com.wwj.core.wawa.service.IPlayerService;
import com.wwj.framework.controller.BaseController;
import com.wwj.framework.utils.Page2EasyUiData;
import com.wwj.framework.utils.ReturnData;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by Auser on 2017/11/3.
 */
@Controller
@RequestMapping(value = "/player/info")
public class PlayerInfoController extends BaseController {

    private final String INDEX = "/admin/player/info";
    @Resource
    private IPlayerService playerService;

    @RequestMapping(value = {"","/","/index"})
    public String index()throws Exception{
        return INDEX;
    }

    @RequestMapping("/list/data.json")
    @ResponseBody
    public ReturnData list(String search,int limit,int offset)throws Exception{
        return new ReturnData()
                .success(Page2EasyUiData
                        .format(playerService
                        .selectPlayerByPage(search,limit,offset)));
    }

    @RequestMapping("/changeStatus/{id}")
    @ResponseBody
    public ReturnData changeStatus(@PathVariable("id") int id)throws Exception{
        playerService.updateStatus(id);
        return new ReturnData().success("ok");
    }

    @RequestMapping(value = "/list_by_invitor/{invitorId}")
    @ResponseBody
    public ReturnData listByInvitorId(@PathVariable("invitorId") int invitorId, String search, int limit, int offset)throws Exception{
        Player invitor = playerService.findById(invitorId);
        if(invitor == null) {
            return new ReturnData().failure("找不到邀请人信息!");
        }
        List<Player> list = playerService.selectPlayerByInvitorInPage(invitorId, search, limit, offset);
        return new ReturnData().success(Page2EasyUiData.format(list));
    }
}
